package com.lushuan.ch11_springboot_test.demo.threadpool;

public class SimpleThreadExample {

    public static void main(String[] args) {
        // 使用Thread创建线程
        Thread thread1 = new Thread(() -> {
            for (int i = 1; i <= 5; i++) {
                System.out.println("Thread 1: " + i);
                try {
                    Thread.sleep(100); // 使线程休眠
                } catch (InterruptedException e) {
                    Thread.currentThread().interrupt();
                }
            }
        });

        // 使用Runnable接口创建线程
        Runnable runnableTask = () -> {
            for (int i = 1; i <= 5; i++) {
                System.out.println("Thread 2: " + i);
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    Thread.currentThread().interrupt();
                }
            }
        };
        Thread thread2 = new Thread(runnableTask);

        // 启动线程
        thread1.start();
        thread2.start();
    }
}

